import 'package:flutter/material.dart';
import 'package:xv_flutter/router/application.dart';
import 'package:xv_flutter/utils/http.dart';

class AboutUsPage extends StatefulWidget {
  @override
  _AboutUsPageState createState() => _AboutUsPageState();
}

class _AboutUsPageState extends State<AboutUsPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        color: Colors.white,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Image.asset('assets/images/products/1.jpeg', fit: BoxFit.cover),
            ListTile(
                leading: Icon(Icons.message),
                title: Text('公司介绍'),
                onTap: () {
                  Application.router.navigateTo(context, 'web');
                }),
            Divider(height: 10, color: Colors.grey),
            ListTile(leading: Icon(Icons.info), title: Text('公司优势')),
            Divider(height: 10, color: Colors.grey),
            ListTile(
              leading: Icon(Icons.phone),
              title: Text('联系我们'),
              onTap: () {
                Application.router.navigateTo(context, 'about_contact');
              },
            ),
            Divider(height: 10, color: Colors.grey),
          ],
        ),
      ),
    );
  }
}

class AboutContactPage extends StatefulWidget {
  @override
  _AboutContactPageState createState() => _AboutContactPageState();
}

class _AboutContactPageState extends State<AboutContactPage> {
  TextEditingController controller = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('给我留言')),
      body: Container(
        color: Colors.white,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Image.asset('assets/images/products/1.jpeg', fit: BoxFit.cover),
            SizedBox(height: 40),
            SizedBox(
              width: 380,
              child: TextField(
                controller: controller,
                decoration: InputDecoration(
                  hintText: '请留言',
                  labelText: '请留言',
                  border: OutlineInputBorder(),
                  prefixIcon: Icon(Icons.person),
                ),
              ),
            ),
            SizedBox(height: 40),
            SizedBox(
              width: 220,
              height: 48,
              child: RaisedButton(
                child: Text('给我们留言', style: TextStyle(fontSize: 16)),
                color: Theme.of(context).primaryColor,
                colorBrightness: Brightness.dark,
                textColor: Colors.white,
                padding:
                    EdgeInsets.only(left: 20, right: 20, top: 5, bottom: 5),
                shape: RoundedRectangleBorder(
                  side: BorderSide(
                    width: 1,
                    color: Colors.white,
                    style: BorderStyle.solid,
                  ),
                  borderRadius: BorderRadius.only(
                    topRight: Radius.circular(4),
                    topLeft: Radius.circular(4),
                    bottomLeft: Radius.circular(4),
                    bottomRight: Radius.circular(4),
                  ),
                ),
                onPressed: () {
                  commit();
                },
              ),
            )
          ],
        ),
      ),
    );
  }

  // 提交数据
  commit() {
    if (controller.text.length == 0) {
      showDialog(
          context: context,
          builder: (context) => AlertDialog(title: Text('请输入内容')));
    } else {
      var fromData = {
        "msg": controller.text,
      };
      request('contactCompany', formData: fromData).then((value) {
        print(value);
      });
    }
  }
}
